// Decompiled by DJ v3.9.9.91 Copyright 2005 Atanas Neshkov  Date: 2008-6-29 21:35:21
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   t_user_EditMap.java

package com.creawor.hz_market.t_user;

import com.creawor.hz_market.t_role.t_role;
import com.creawor.hz_market.t_user_role.t_user_role;
import com.creawor.imei.base.AbsEditMap;
import java.util.Iterator;
import java.util.Set;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Session;

// Referenced classes of package com.creawor.hz_market.t_user:
//            t_user, t_user_Form

public class t_user_EditMap extends AbsEditMap
{

    public t_user_EditMap()
    {
    }

    public void add(t_user_Form vo)
        throws HibernateException
    {
        t_user po = new t_user();
        try
        {
            po.setUsername(vo.getUsername());
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        try
        {
            po.setPassword(vo.getPassword());
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        try
        {
            po.setDept_code(vo.getDept_code());
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        try
        {
            po.setUsercode(vo.getUsercode());
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        try
        {
            po.setMobile(vo.getMobile());
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        try
        {
            po.setEmail(vo.getEmail());
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        po.setDepartment(vo.getDepartment());
        Session session = beginTransaction();
        try
        {
            session.save(po);
            String roleIds[] = vo.getRole_id();
            save_t_user_roles(po, session, roleIds);
            endTransaction(true);
        }
        catch(Exception e)
        {
            endTransaction(false);
            e.printStackTrace();
            throw new HibernateException(e);
        }
    }

    private void save_t_user_roles(t_user po, Session session, String roleIds[])
        throws HibernateException
    {
        for(int i = 0; i < roleIds.length; i++)
            session.save(new t_user_role(po.getId(), Integer.parseInt(roleIds[i])));

    }

    public void delete(t_user_Form vo)
        throws HibernateException
    {
        String id = vo.getId();
        delete(id);
    }

    public void delete(String id)
        throws HibernateException
    {
        Session session = beginTransaction();
        try
        {
            t_user po = (t_user)session.load(t_user.class, new Integer(id));
            session.delete(po);
            endTransaction(true);
        }
        catch(HibernateException e)
        {
            e.printStackTrace();
            endTransaction(false);
        }
    }

    public void update(t_user_Form vo)
        throws HibernateException
    {
        Session session = beginTransaction();
        String id = vo.getId();
        t_user po = (t_user)session.load(t_user.class, new Integer(id));
        try
        {
            po.setId(Integer.parseInt(vo.getId()));
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        try
        {
            po.setUsername(vo.getUsername());
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        try
        {
            po.setPassword(vo.getPassword());
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        try
        {
            po.setDept_code(vo.getDept_code());
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        try
        {
            po.setUsercode(vo.getUsercode());
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        try
        {
            po.setMobile(vo.getMobile());
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        try
        {
            po.setEmail(vo.getEmail());
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        po.setDepartment(vo.getDepartment());
        try
        {
            session.update(po);
            t_role role;
            for(Iterator it = po.getRoles().iterator(); it.hasNext(); session.delete(new t_user_role(po.getId(), role.getId())))
                role = (t_role)it.next();

            save_t_user_roles(po, session, vo.getRole_id());
            endTransaction(true);
        }
        catch(Exception e)
        {
            endTransaction(false);
            e.printStackTrace();
            throw new HibernateException(e);
        }
    }

    

    static Class class$0;
}